package com.green.web.controller.manage;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.green.model.manage.Area;
import com.green.service.manage.AreaService;
import com.green.web.controller.common.BaseController;

/**
 * 区域控制类(省、市、区..)
 * 
 * @author 胡辉林
 * 
 */
@Controller
@RequestMapping(value = "/area/*")
public class AreaController extends BaseController {

	@Resource
	private AreaService areaService;

	// query省、市等信息
	@RequestMapping(value = "getArea")
	@ResponseBody
	public Map<String, Object> getArea(ModelMap modelMap) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> params = new HashMap<String, Object>();
		String level = getString("level");
		String ids = getString("ids");
		if (null != ids) {
			String[] idList = ids.split(",");
			String areaIds = "";
			for (String obj : idList) {
				if (areaIds == "") {
					areaIds = "'" + obj + "'";
				} else {
					areaIds = areaIds + ",'" + obj + "'";
				}
			}
			params.put("areaIds", areaIds);
			
			if(null!=level&&level.equals("5")){
			 params.put("existslevel", "existslevel");//查询没有被使用过的数据
			}
		}
		String parentId = getString("parentId");
		String personId = getString("personId");
		params.put("level", level);
		params.put("parentId", parentId);
		params.put("personId", personId);
		List<Area> areaList = areaService.getAreaList(params);
		resultMap.put("areaList", areaList);
		return resultMap;
	}

}
